#include <bits/stdc++.h>
// 2025/04/04
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, s[201], dp1[201][201], dp2[201][201];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> s[i], s[i + n] = s[i];
    for (int i = 1; i <= 2 * n; i++)
        s[i] += s[i - 1];
    for (int len = 2; len <= n; len++)
        for (int l = 1; l + len - 1 <= 2 * n; l++)
        {
            int r = l + len - 1;
            for (int k = l; k < r; k++)
                dp2[l][r] = min(dp2[l][r] == 0 ? INT_MAX : dp2[l][r], dp2[l][k] + dp2[k + 1][r] + s[r] - s[l - 1]), dp1[l][r] = max(dp1[l][r], dp1[l][k] + dp1[k + 1][r] + s[r] - s[l - 1]);
        }
    int ans1 = INT_MAX, ans2 = 0;
    for (int i = 1; i <= n; i++)
        ans1 = min(ans1, dp2[i][i + n - 1]);
    for (int i = 1; i <= n; i++)
        ans2 = max(ans2, dp1[i][i + n - 1]);
    cout << ans1 << endl << ans2 << endl;
    return 0;
}